/**
 * WMS基础数据API服务类
 */
import request from "@/utils/http";

// 导入新的WMS API服务
export { WmsCheckOrderService, checkOrderApiConfig } from './checkOrderApi'
export { WmsInventoryDetailService, inventoryDetailApiConfig } from './inventoryDetailApi'
export { WmsInventoryService, inventoryApiConfig } from './inventoryApi'

/**
 * 仓库管理API服务
 */
export class WmsWarehouseService {
  /**
   * 获取仓库列表
   */
  static getWarehouseList(params?: WMS.Basic.WarehouseQueryParams) {
    return request.get<WMS.Basic.WarehouseListResponse>({
      url: "/wms/warehouse/list",
      params,
    });
  }

  /**
   * 获取仓库详情
   */
  static getWarehouseDetail(id: number) {
    return request.get<WMS.Basic.WarehouseInfo>({
      url: `/wms/warehouse/${id}`,
    });
  }

  /**
   * 创建仓库
   */
  static createWarehouse(
    data: Omit<WMS.Basic.WarehouseInfo, "id" | "createTime" | "updateTime">,
  ) {
    return request.post<WMS.Basic.WarehouseInfo>({
      url: "/wms/warehouse",
      data,
    });
  }

  /**
   * 更新仓库
   */
  static updateWarehouse(id: number, data: Partial<WMS.Basic.WarehouseInfo>) {
    return request.put<WMS.Basic.WarehouseInfo>({
      url: `/wms/warehouse/${id}`,
      data,
    });
  }

  /**
   * 删除仓库
   */
  static deleteWarehouse(id: number) {
    return request.del<void>({
      url: `/wms/warehouse/${id}`,
    });
  }

  /**
   * 获取所有仓库（不分页）
   */
  static getAllWarehouses() {
    return request.get<WMS.Basic.WarehouseInfo[]>({
      url: "/wms/warehouse/listNoPage",
    });
  }
}

/**
 * 库区管理API服务
 */
export class WmsAreaService {
  /**
   * 获取库区列表
   */
  static getAreaList(params?: WMS.Basic.AreaQueryParams) {
    return request.get<WMS.Basic.AreaListResponse>({
      url: "/wms/area/list",
      params,
    });
  }

  /**
   * 获取库区详情
   */
  static getAreaDetail(id: number) {
    return request.get<WMS.Basic.AreaInfo>({
      url: `/wms/area/${id}`,
    });
  }

  /**
   * 创建库区
   */
  static createArea(
    data: Omit<WMS.Basic.AreaInfo, "id" | "createTime" | "updateTime">,
  ) {
    return request.post<WMS.Basic.AreaInfo>({
      url: "/wms/area",
      data,
    });
  }

  /**
   * 更新库区
   */
  static updateArea(id: number, data: Partial<WMS.Basic.AreaInfo>) {
    return request.put<WMS.Basic.AreaInfo>({
      url: `/wms/area/${id}`,
      data,
    });
  }

  /**
   * 删除库区
   */
  static deleteArea(id: number) {
    return request.del<void>({
      url: `/wms/area/${id}`,
    });
  }

  /**
   * 根据仓库ID获取库区列表
   */
  static getAreasByWarehouse(warehouseId: number) {
    return request.get<WMS.Basic.AreaInfo[]>({
      url: `/wms/area/warehouse/${warehouseId}`,
    });
  }

  /**
   * 获取所有库区（不分页）
   */
  static getAllAreas() {
    return request.get<WMS.Basic.AreaInfo[]>({
      url: "/wms/area/listNoPage",
    });
  }
}

/**
 * 商户管理API服务
 */
export class WmsMerchantService {
  /**
   * 获取商户列表
   */
  static getMerchantList(params?: WMS.Basic.MerchantQueryParams) {
    return request.get<WMS.Basic.MerchantListResponse>({
      url: "/wms/merchant/list",
      params,
    });
  }

  /**
   * 获取商户详情
   */
  static getMerchantDetail(id: number) {
    return request.get<WMS.Basic.MerchantInfo>({
      url: `/wms/merchant/${id}`,
    });
  }

  /**
   * 创建商户
   */
  static createMerchant(
    data: Omit<WMS.Basic.MerchantInfo, "id" | "createTime" | "updateTime">,
  ) {
    return request.post<WMS.Basic.MerchantInfo>({
      url: "/wms/merchant",
      data,
    });
  }

  /**
   * 更新商户
   */
  static updateMerchant(id: number, data: Partial<WMS.Basic.MerchantInfo>) {
    return request.put<WMS.Basic.MerchantInfo>({
      url: `/wms/merchant/${id}`,
      data,
    });
  }

  /**
   * 删除商户
   */
  static deleteMerchant(id: number) {
    return request.del<void>({
      url: `/wms/merchant/${id}`,
    });
  }

  /**
   * 获取所有商户（不分页）
   */
  static getAllMerchants() {
    return request.get<WMS.Basic.MerchantInfo[]>({
      url: "/wms/merchant/listNoPage",
    });
  }
}

/**
 * 商品分类管理API服务
 */
export class WmsItemCategoryService {
  /**
   * 获取商品分类列表
   */
  static getItemCategoryList(params?: WMS.Basic.ItemCategoryQueryParams) {
    return request.get<WMS.Basic.ItemCategoryListResponse>({
      url: "/wms/itemCategory/list",
      params,
    });
  }

  /**
   * 获取商品分类树形结构
   */
  static getItemCategoryTree() {
    return request.get<WMS.Basic.ItemCategoryTreeInfo[]>({
      url: "/wms/itemCategory/tree",
    });
  }

  /**
   * 获取商品分类详情
   */
  static getItemCategoryDetail(id: number) {
    return request.get<WMS.Basic.ItemCategoryInfo>({
      url: `/wms/itemCategory/${id}`,
    });
  }

  /**
   * 创建商品分类
   */
  static createItemCategory(
    data: Omit<WMS.Basic.ItemCategoryInfo, "id" | "createTime" | "updateTime">,
  ) {
    return request.post<WMS.Basic.ItemCategoryInfo>({
      url: "/wms/itemCategory",
      data,
    });
  }

  /**
   * 更新商品分类
   */
  static updateItemCategory(
    id: number,
    data: Partial<WMS.Basic.ItemCategoryInfo>,
  ) {
    return request.put<WMS.Basic.ItemCategoryInfo>({
      url: `/wms/itemCategory/${id}`,
      data,
    });
  }

  /**
   * 删除商品分类
   */
  static deleteItemCategory(id: number) {
    return request.del<void>({
      url: `/wms/itemCategory/${id}`,
    });
  }

  /**
   * 获取所有商品分类（不分页）
   */
  static getAllItemCategories() {
    return request.get<WMS.Basic.ItemCategoryInfo[]>({
      url: "/wms/itemCategory/listNoPage",
    });
  }
}

/**
 * 商品品牌管理API服务
 */
export class WmsItemBrandService {
  /**
   * 获取商品品牌列表
   */
  static getItemBrandList(params?: WMS.Basic.ItemBrandQueryParams) {
    return request.get<WMS.Basic.ItemBrandListResponse>({
      url: "/wms/itemBrand/list",
      params,
    });
  }

  /**
   * 获取商品品牌详情
   */
  static getItemBrandDetail(id: number) {
    return request.get<WMS.Basic.ItemBrandInfo>({
      url: `/wms/itemBrand/${id}`,
    });
  }

  /**
   * 创建商品品牌
   */
  static createItemBrand(
    data: Omit<WMS.Basic.ItemBrandInfo, "id" | "createTime" | "updateTime">,
  ) {
    return request.post<WMS.Basic.ItemBrandInfo>({
      url: "/wms/itemBrand",
      data,
    });
  }

  /**
   * 更新商品品牌
   */
  static updateItemBrand(id: number, data: Partial<WMS.Basic.ItemBrandInfo>) {
    return request.put<WMS.Basic.ItemBrandInfo>({
      url: `/wms/itemBrand/${id}`,
      data,
    });
  }

  /**
   * 删除商品品牌
   */
  static deleteItemBrand(id: number) {
    return request.del<void>({
      url: `/wms/itemBrand/${id}`,
    });
  }

  /**
   * 获取所有商品品牌（不分页）
   */
  static getAllItemBrands() {
    return request.get<WMS.Basic.ItemBrandInfo[]>({
      url: "/wms/itemBrand/listNoPage",
    });
  }
}

/**
 * 商户余额管理API服务
 * 参照原项目 RuoYi-WMS-VUE/src/api/wms/merchantBalance.js
 */
export class WmsMerchantBalanceService {
  /**
   * 获取应收账款列表
   */
  static getMerchantBalanceList(params?: WMS.Basic.MerchantBalanceQueryParams) {
    return request.get<WMS.Basic.MerchantBalanceListResponse>({
      url: "/wms/merchantBalance/list",
      params,
    });
  }

  /**
   * 获取应收账款详情
   */
  static getMerchantBalance(id: number) {
    return request.get<WMS.Basic.MerchantBalanceInfo>({
      url: `/wms/merchantBalance/${id}`,
    });
  }

  /**
   * 根据客户ID查询应收账款
   */
  static getMerchantBalanceByMerchantId(merchantId: number) {
    return request.get<WMS.Basic.MerchantBalanceInfo>({
      url: `/wms/merchantBalance/merchant/${merchantId}`,
    });
  }

  /**
   * 新增应收账款
   */
  static createMerchantBalance(
    data: Omit<WMS.Basic.MerchantBalanceInfo, "id" | "createTime" | "updateTime">,
  ) {
    return request.post<WMS.Basic.MerchantBalanceInfo>({
      url: "/wms/merchantBalance",
      data,
    });
  }

  /**
   * 修改应收账款
   */
  static updateMerchantBalance(id: number, data: Partial<WMS.Basic.MerchantBalanceInfo>) {
    return request.put<WMS.Basic.MerchantBalanceInfo>({
      url: `/wms/merchantBalance/${id}`,
      data,
    });
  }

  /**
   * 删除应收账款
   */
  static deleteMerchantBalance(id: number) {
    return request.del<void>({
      url: `/wms/merchantBalance/${id}`,
    });
  }

  /**
   * 更新客户应收账款余额
   */
  static updateMerchantBalanceAmount(data: {
    merchantId: number;
    amount: number;
    remark?: string;
  }) {
    return request.post<void>({
      url: "/wms/merchantBalance/updateBalance",
      params: data,
    });
  }

  /**
   * 获取应收账款统计信息
   */
  static getMerchantBalanceStatistics() {
    return request.get<WMS.Basic.MerchantBalanceStatistics>({
      url: "/wms/merchantBalance/statistics",
    });
  }
}

/**
 * 商户余额明细API服务
 * 参照原项目 RuoYi-WMS-VUE/src/api/wms/merchantBalanceDetail.js
 */
export class WmsMerchantBalanceDetailService {
  /**
   * 获取应收账款明细列表
   */
  static getMerchantBalanceDetailList(params?: WMS.Basic.MerchantBalanceDetailQueryParams) {
    return request.get<WMS.Basic.MerchantBalanceDetailListResponse>({
      url: "/wms/merchantBalanceDetail/list",
      params,
    });
  }

  /**
   * 获取应收账款明细详情
   */
  static getMerchantBalanceDetail(id: number) {
    return request.get<WMS.Basic.MerchantBalanceDetailInfo>({
      url: `/wms/merchantBalanceDetail/${id}`,
    });
  }

  /**
   * 根据客户ID查询应收账款明细列表
   */
  static getMerchantBalanceDetailByMerchant(merchantId: number, params?: WMS.Basic.MerchantBalanceDetailQueryParams) {
    return request.get<WMS.Basic.MerchantBalanceDetailListResponse>({
      url: `/wms/merchantBalanceDetail/merchant/${merchantId}`,
      params,
    });
  }

  /**
   * 新增应收账款明细
   */
  static createMerchantBalanceDetail(
    data: Omit<WMS.Basic.MerchantBalanceDetailInfo, "id" | "createTime" | "updateTime">,
  ) {
    return request.post<WMS.Basic.MerchantBalanceDetailInfo>({
      url: "/wms/merchantBalanceDetail",
      data,
    });
  }

  /**
   * 修改应收账款明细
   */
  static updateMerchantBalanceDetail(id: number, data: Partial<WMS.Basic.MerchantBalanceDetailInfo>) {
    return request.put<WMS.Basic.MerchantBalanceDetailInfo>({
      url: `/wms/merchantBalanceDetail/${id}`,
      data,
    });
  }

  /**
   * 删除应收账款明细
   */
  static deleteMerchantBalanceDetail(id: number) {
    return request.del<void>({
      url: `/wms/merchantBalanceDetail/${id}`,
    });
  }

  /**
   * 获取应收账款明细统计
   */
  static getMerchantBalanceDetailStatistics(merchantId: number) {
    return request.get<WMS.Basic.MerchantBalanceDetailStatistics>({
      url: `/wms/merchantBalanceDetail/statistics/${merchantId}`,
    });
  }
}

/**
 * 基础数据综合API服务
 */
export class WmsBasicService {
  // 仓库相关
  static getWarehouseList = WmsWarehouseService.getWarehouseList;
  static getAllWarehouses = WmsWarehouseService.getAllWarehouses;

  // 库区相关
  static getAreaList = WmsAreaService.getAreaList;
  static getAreasByWarehouse = WmsAreaService.getAreasByWarehouse;
  static getAllAreas = WmsAreaService.getAllAreas;

  // 商户相关
  static getMerchantList = WmsMerchantService.getMerchantList;
  static getAllMerchants = WmsMerchantService.getAllMerchants;

  // 商户余额相关
  static getMerchantBalanceList = WmsMerchantBalanceService.getMerchantBalanceList;
  static getMerchantBalanceStatistics = WmsMerchantBalanceService.getMerchantBalanceStatistics;

  // 商户余额明细相关
  static getMerchantBalanceDetailList = WmsMerchantBalanceDetailService.getMerchantBalanceDetailList;
  static getMerchantBalanceDetailByMerchant = WmsMerchantBalanceDetailService.getMerchantBalanceDetailByMerchant;

  // 商品分类相关
  static getItemCategoryList = WmsItemCategoryService.getItemCategoryList;
  static getItemCategoryTree = WmsItemCategoryService.getItemCategoryTree;
  static getAllItemCategories = WmsItemCategoryService.getAllItemCategories;

  // 商品品牌相关
  static getItemBrandList = WmsItemBrandService.getItemBrandList;
  static getAllItemBrands = WmsItemBrandService.getAllItemBrands;
}
